﻿using System;
using System.Text;

namespace Tab2Sql
{
    /// <summary>
    /// General error handler. Feature incomplete.
    /// </summary>
    public class Err
    {
        #region errorRating enum

        /// <summary>
        /// subjective error scale
        /// </summary>
        public enum errorRating
        {
            /// <summary>
            /// Normal paramers.
            /// </summary>
            OK,
            /// <summary>
            /// No problem. Message simply for info.
            /// </summary>
            Info,
            /// <summary>
            /// Suboptimal situation exists, but not enough to warrant concern.
            /// </summary>
            Issue,
            /// <summary>
            /// Normal function is not possible due to situation.
            /// </summary>
            Problem,
            /// <summary>
            /// PANIC!
            /// </summary>
            OMFG,
            /// <summary>
            /// Unknown/Default error.
            /// </summary>
            Unknown
        }

        #endregion

        private StringBuilder errorLog;
        /// <summary>
        ///
        /// </summary>
        public StringBuilder ErrorLog
        {
            get { return errorLog; }
            set { errorLog = value; }
        }
        private DateTime invokeTime;


        /// <summary>
        /// status code. 0 = all good.
        /// </summary>
        private int status;
        /// <summary>
        /// 
        /// </summary>
        public int Status
        {
            get { return status; }
            set { status = value; }
        }

        /// <summary>
        /// Create err object.
        /// </summary>
        /// <param name="source">class name which called this.</param>
        public Err(string source)
        {
            Status = 0;
            invokeTime = DateTime.Now;
            errorLog = new StringBuilder();
        }

        /// <summary>
        /// Returns error log in full.
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return errorLog.ToString();
        }

        /// <summary>
        /// Add to error log.
        /// </summary>
        /// <param name="msg"></param>
        public void Add(string msg)
        {
            Add(msg, errorRating.Unknown);
            Status++;
        }

        /// <summary>
        /// Add to error log.
        /// </summary>
        /// <param name="msg">description of error</param>
        /// <param name="errScore">seriousness of error</param>
        public void Add(string msg, errorRating errScore)
        {
            errorLog.AppendLine(DateTime.Now.ToLongTimeString() + "\t" + errScore.ToString());
            Status++;
        }
    }
}